import { createRouter, createWebHistory } from "vue-router";
import Layout from "@/pages/layout/index.vue";
import ChildLayout from "@/pages/layout/child-layout.vue";

const router = createRouter({
    history: createWebHistory(),
    routes: [
        {
            path: "/",
            component: Layout,
            redirect: "/home",
            meta: {
                title: '首页'
            },
            children: [
                {
                    path: "/home",
                    meta: {
                        title: "首页",
                    },
                    component: () => import("@/pages/home/index.vue"),
                },
                {
                    path: "/industrial-dynamics",
                    meta: {
                        title: "行业新闻",
                    },
                    component: ChildLayout,
                    children: [
                        {
                            path: "/industrial-dynamics",
                            meta: {
                                title: "产业动态",
                            },
                            component: () => import("@/pages/trade-news/industrial-dynamics.vue"),
                        },
                    ]
                },
                {
                    path: "/public-mooc",
                    meta: {
                        title: "公益MOCC",
                    },
                    component: () => import("@/pages/public-mooc/index.vue"),
                },
                {
                    path: "/activity",
                    meta: {
                        title: "活动专场",
                    },
                    component: () => import("@/pages/activity/index.vue"),
                },
                {
                    path: "/expert-thinkTank",
                    meta: {
                        title: "专家&智库",
                    },
                    component: () => import("@/pages/expert-thinkTank/index.vue"),
                },
                {
                    path: "/aboutUs",
                    meta: {
                        title: "关于本会",
                    },
                    component: () => import("@/pages/aboutUs/index.vue"),
                },
            ],
        },
    ],
});

router.beforeEach((to) => {
    if(to.meta?.title) {
        document.title = '元宇宙-' + to.meta.title
    }else{
        document.title = '元宇宙'
    }
});
export default router;